package com.studentrecipe.mapper;

import com.studentrecipe.pojo.Comment;
import com.studentrecipe.pojo.Like;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MapperComment {

    @Select("select * from ipd.like where recipe_id = #{recipe_id}")
    List<Like> getLike(Integer recipe_id);

    @Select("select * from ipd.comment where recipe_id = #{recipe_id} order by id desc")
    List<Comment> getComment(Integer recipe_id);

    Double getScore(Integer recipe_id);

    @Insert("insert into ipd.comment(student_id, recipe_id, comment) values(#{student_id}, #{recipe_id}, #{comment})")
    boolean makeComment(Integer student_id, Integer recipe_id, String comment);

    @Delete("delete from ipd.comment where id = #{id}")
    boolean deleteComment(Integer id);

    @Select("select * from ipd.`like` where student_id = #{student_id} and recipe_id = #{recipe_id}")
    Like getOneLike(Integer student_id, Integer recipe_id);

    @Insert("insert into ipd.`like`(student_id, recipe_id, `like`) values(#{student_id}, #{recipe_id}, 1)")
    boolean makeLike(Integer student_id, Integer recipe_id);

    Integer changeLike(Integer student_id, Integer recipe_id);

    @Insert("insert into ipd.`like`(student_id, recipe_id, score) values(#{student_id}, #{recipe_id}, #{score})")
    boolean makeScore(Integer student_id, Integer recipe_id, Integer score);

    @Update("update ipd.`like` set score = #{score} where student_id = #{student_id} and recipe_id = #{recipe_id}")
    Integer updateScore(Integer student_id, Integer recipe_id, Integer score);

}